import type { ArticleData } from '@/types/article'
import type { EditArticleRes, ResImages } from '@/types/publish'
import service, { request } from '@/utils/request'

export const uploadAPI = (image: FormData) => {
  return request<ResImages>('/v1_0/upload', 'POST', image)
}

// 编辑文章
export const EditArticleAPI = (id: string) => {
  return request<EditArticleRes>(`/v1_0/mp/articles/${id}`, 'GET')
}

// 发布文章
export const publishAPI = async (params: ArticleData, draft?: boolean) => {
  return await service.post('/v1_0/mp/articles', params, { params: { draft } })
}
// 编辑文章
export const updateArticleAPI = async (id: string, params: ArticleData, draft?: boolean) => {
  return await service.put(`/v1_0/mp/articles/${id}`, params, { params: { draft } })
}

// 回显数据-获取文章详情
export const getArticleDetailAPI = async (id: string) => {
  return await service.get<EditArticleRes>(`/v1_0/mp/articles/${id}`)
}
